#!/bin/bash -e

function info() {
echo Usage: `basename $0` '[-s fs -t] file'
exit 1
}

while getopts  ":p:f:s:t" opt; do
	case  $opt  in
        p) out_prefix=$OPTARG;;
        f) suffix=$OPTARG;;
        t) col_less=true;;
        s) fs="$OPTARG";;
        *) info;;
	esac
done
shift $(($OPTIND - 1))

if [ $# -lt 1 ]; then info; fi

. $var

fs=${fs:='\t'}

if $col_less; then
    nr=`awk -v fs="$fs" '{print NF; exit 0}' $1`
    for i in `seq 1 $nr`; do cut -f$i $1|awk 'BEGIN{ORS="\t"}{print}'|sed '$s/\t$/\n/'; done > ${out_prefix}_
    . $cmd_done
fi


awk '{print > '"${out_prefix:=1}"'  ".trans0." NR}END{print FNR > "nr"}' $1



for i in `seq $(cat nr)`; do 
    awk -v fs="$fs" 'BEGIN{RS=fs; ORS="\n"}{print}' $out_prefix.trans0.${i} > $out_prefix.trans.${i}
done

paste $out_prefix.trans.* |awk '$0!~/^[ \t]/' > ${out_prefix}_

rm $out_prefix.trans.* $out_prefix.trans0.* nr



. $cmd_done